<?php
class buyMod extends commonMod{

	// 购买
	public function index() {

		$proid = intval($_GET['pid']);
		$this->assign('proid', $proid);

		$this->display('buy_index');
	}

	// 购买提交
	public function post() {

		if ($_POST) {
			// 处理留言
			
			$proid 	 = __safe('proid');
			$num 	 = (int) intval(__safe('num'));
			$name 	 = __safe('name');
			$tel 	 = __safe('tel');
			$vcode   = __safe('vcode');

			// 默认买一件
			if (empty($num)) $num =1;

			// 验证码
			if ($_SESSION['lebang_vcode'] != $vcode or $vcode=='') {
				echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
				echo '<script>alert(\'验证码有误\');history.go(-1);</script>';
				exit;
			}

			// 数据是否为空
			if (empty($proid) or empty($num) or empty($name) or empty($tel)) {
				echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
				echo '<script>alert(\'联系人、电话、是必填项\');history.go(-1);</script>';
				exit;
			}

			$title = '产品名称：'.get_proname($proid).chr(10).'产品单价：'.get_proprice($proid).chr(10).'产品数量：'.$num.chr(10).'合计：'.(get_proprice($proid)*$num);
			$content = '联系人：'.$name.chr(10).'电话：'.$tel;

			@__query("INSERT INTO {tabpre}orders (`title`, `content`, `datetime`, `show`, `recover`) VALUES ('$title', '$content', '".date('Y-m-d h:i:s')."', 0, 0) ");

			echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
			echo '<script>alert(\'订单提交成功，我们会尽快与您取得联系，服务热线：0571-88887777\');history.go(-1);</script>';
			exit;
		}
	}
}